<template>
  <div class="header_ref">
    <div class="tabs_box">
      <ul>
        <li class="active">知识元管理</li>
      </ul>
    </div>
    <div class="search">
      <el-input clearable placeholder="按知识元名称搜索" prefix-icon="el-icon-search" v-model="searchText" @keydown.enter="searchHandle" @clear="searchHandle" />
    </div>
    <div class="btns" >
      <el-button round @click="add">新建知识元</el-button>
    </div>
  </div>
</template>
<script lang="ts">
import { ref, onMounted } from 'vue';
import AddDialog from "./add-dialog.vue";
import { emitter, modal } from '$';

export default {
  props: ['getKnowledge'],
  setup(props, { emit }) {
    let selectData = []

    let searchText = ref(null);
    const searchHandle = () => emit('search', { type: 'title', value: searchText.value});

    onMounted(() => {
      emitter.on('knowledge-selected', (e) => { selectData = e })
    })
    const add = () => {
      props.getKnowledge().then(() => {
        modal.create({ 
          title: '新建知识元',
          width: 640,
          zIndex:998,
          component: AddDialog,
          props: { selectData },
        })
      })
    }

    return { add, searchText, searchHandle }
  }
}
</script>
<style lang="scss" scoped>
.header_ref {
  display: flex;
  line-height: 60px;
  .tabs_box {
    li {
      float: left;
      padding: 0 20px;
      color: #fff;
      list-style: none;
      position: relative;
      cursor: pointer;
      &.active::after {
        content: '';
        display: block;
        width: 100%;
        height: 6px;
        background: #FAAD14;
        border-radius: 3px;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
  .search {
    margin-left: auto;
    :deep(.el-input__prefix),
    :deep(.el-input__suffix) {
      color: #fff !important;
    }
    :deep(input) {
      width: 220px;
      height: 36px;
      color: #fff;
      border: 0;
      border-radius: 18px;
      background: rgba(255, 255, 255, 0.3);
      &::placeholder {
        color: rgba(255, 255, 255, .7);
      }
    }
  }
  .btns {
    margin-left: 20px;
    button {
      color: #72b22a;
      padding: 10px 23px;
    }
  }
}
</style>